import koa from 'castle-koa'
import {RPC} from 'castle-koa/dist/utils/ws'
import * as net from 'net'
koa.listen(8000)
export const server = net.createServer()
server.listen(8001);
export const sockets=[];
server.on('connection',(socket)=>{
    socket.on('data',(data)=>{
        RPC.publish('down',data.toString())
    })
    socket.on('close',()=>{
        sockets.splice(sockets.indexOf(socket),1)
    })
    sockets.push(socket)
})
RPC.subscribe('up',(data)=>{
    sockets.forEach((s)=>{
        s.write(data)
    })
})